package com.tool.cn.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Map;


/**
 * 模型工具类
 * @author wangzh
 * @date 2018年8月2日 上午10:01:28
 */
public class TemplateUtil {
	
	/**
	 * 
	 * @param modelUrl
	 * @param outUrl
	 * @param paramMap
	 */
	public static void createFiel(String modelUrl,String outUrl,Map<String,String> paramMap){
		try {
			BufferedReader buf=new BufferedReader(new InputStreamReader(new FileInputStream(modelUrl)));
			
			BufferedWriter write=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outUrl)));
			String context="";
			String paramReally="";
			while((context=buf.readLine())!=null){
				for(String param:paramMap.keySet()){
					paramReally="~"+param+"~";
					if(context.contains(paramReally)){
						context=context.replaceAll(paramReally, paramMap.get(param));
					}
				}
				write.write(context+System.getProperty("line.separator"));
			}
			
			write.flush();
			write.close();
			buf.close();
			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
}
